#
# @lc app=leetcode.cn id=66 lang=python
#
# [66] 加一
#

# @lc code=start
class Solution(object):
    def plusOne(self, digits):
        """
        :type digits: List[int]
        :rtype: List[int]
        """
        digits_reverse = digits[::-1]
        digits_reverse[0] += 1
        for i in range(len(digits_reverse)-1):
            if digits_reverse[i] > 9:
                digits_reverse[i] -= 10
                digits_reverse[i+1] += 1
        if digits_reverse[-1] > 9:
            digits_reverse[-1] -= 10
            digits_reverse.append(1)
        return digits_reverse[::-1]

# @lc code=end


if __name__ == "__main__":
    solution = Solution()
    result = solution.plusOne([9, 9])
    print(result)